package isquirrel.servlets;

import isquirrel.FacebookAPI;
import isquirrel.UserManager;
import isquirrel.beans.User;
import isquirrel.servlets.handler.HttpDBServlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import javax.servlet.ServletException;

import org.json.JSONException;

/**
 * Servlet implementation class FindFriends
 */
public class FindFriends extends HttpDBServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * Default constructor.
	 */
	public FindFriends() {
	}

	@Override
	protected void handleGet() throws ServletException, IOException,
			JSONException {

	}

	@Override
	protected void handlePost() throws ServletException, IOException,
			JSONException {
		List<User> result = UserManager.searchUsers(request
				.getParameter("query"));
		result.remove(getLoggedInUser());
		FacebookAPI api = new FacebookAPI();
		
		HashMap<Long,String> users = api.getUsers_PicSquare(result);
		
		request.setAttribute("users", users);
		request.setAttribute("user", getLoggedInUser());
		request.getRequestDispatcher("../views/servlet/FindFriends.jsp")
				.forward(request, response);
	}

}
